var db = {
  //员工
  staff: [
    {
      id: 1,
      name: "张三",
      sex: "男",
      //部门
      department: "销售部",
      //职务
      post: "组长",
      phone: 19999999999,
      //密码
      password: 123456,
      //备注
      remarks: "",
      //业绩目标
      achievement: {},
      //邮箱
      e_mail: 888,
      birthday: "2000-01-2",
    },
    {
      id: 2,
      name: "李四",
      sex: "男",
      //部门
      department: "销售一组",
      //职务
      post: "组长",
      phone: 18888888888,
      //密码
      password: 123456,
      //备注
      remarks: "",
      //业绩目标
      achievement: {},
      //邮箱
      e_mail: 888,
      birthday: "2000-01-2",
    },
    {
      id: 3,
      name: "王五",
      sex: "男",
      //部门
      department: "销售二组",
      //职务
      post: "组长",
      phone: 17777777777,
      //密码
      password: 123456,
      //备注
      remarks: "",
      //业绩目标
      achievement: {},
      //邮箱
      e_mail: 888,
      birthday: "2000-01-2",
    },
    {
      id: 4,
      name: "赵六",
      sex: "女",
      //部门
      department: 1,
      //职务
      post: "组员",
      phone: 16666666666,
      //密码
      password: 123456,
      //备注
      remarks: "",
      //业绩目标
      achievement: {},
      //邮箱
      e_mail: 888,
      birthday: "2000-01-2",
    },
  ],

  //部门
  department: [
    {
      //部门编号
      id: 1,
      name: "销售部",
      //责任人(员工id)
      person_liable: 1,
      //上级部门
      superior_department: 1,
      remarks: "",
    },
    {
      id: 2,
      name: "销售一组",
      //责任人(员工id)
      person_liable: 2,
      //上级部门
      superior_department: 1,
      remarks: "",
    },
    {
      id: 3,
      name: "销售二组",
      //责任人(员工id)
      person_liable: 3,
      //上级部门
      superior_department: 1,
      remarks: "",
    },
  ],

  //产品
  product: [
    {
      id: 1,
      name: "单人床",
      //单价
      unit_price: 1000,
      //规格
      specifications: "套",
      remarks: "",
    },
    {
      id: 2,
      name: "双人床",
      //单价
      unit_price: 1500,
      //规格
      specifications: "件",
      remarks: "",
    },
    {
      id: 3,
      name: "优质上下床",
      //单价
      unit_price: 1600,
      //规格
      specifications: "组",
      remarks: "",
    },
  ],

  //公告
  announcement: [
    {
      //遍历依据
      id: 0,
      //标题
      title: 1,
      //发布人
      issuer: 1,
      //发布时间
      time: 1,
      //发布内容
      content: {
        biaoTi: "",
        neirong: "",
      },
    },
  ],

  //客户
  connection: [
    {
      //隐藏属性，添加自增，用户无法直接修改
      id: 1,
      //客户名称
      name: "企鹅",
      //对接人
      counterpart: 1,
      //客户来源
      source: 1,
      //客户标签
      customer_label: "待开发客户",
      //客户类型
      type: "事业单位或社会团体",
      //客户所在城市
      city: "成都",
      //简介
      remarks: 1,
      //
    },
    {
      //隐藏属性，添加自增，用户无法直接修改
      id: 2,
      //客户名称
      name: "逗狗",
      //对接人
      counterpart: 2,
      //客户来源
      source: "客户介绍",
      //客户标签
      customer_label: "目标客户",
      //客户类型
      type: "私营企业",
      //客户所在城市
      city: "成都",
      //简介
      remarks: 1,
      //
    },
    {
      //隐藏属性，添加自增，用户无法直接修改
      id: 3,
      //客户名称
      name: "逗狗",
      //对接人
      counterpart: 2,
      //客户来源
      source: "客户介绍",
      //客户标签
      customer_label: "目标客户",
      //客户类型
      type: "私营企业",
      //客户所在城市
      city: "成都",
      //简介
      remarks: 1,
      //
    },
    {
      //隐藏属性，添加自增，用户无法直接修改
      id: 4,
      //客户名称
      name: "逗狗",
      //对接人
      counterpart: 2,
      //客户来源
      source: "客户介绍",
      //客户标签
      customer_label: "目标客户",
      //客户类型
      type: "私营企业",
      //客户所在城市
      city: "成都",
      //简介
      remarks: 1,
      //
    },
    {
      //隐藏属性，添加自增，用户无法直接修改
      id: 5,
      //客户名称
      name: "逗狗",
      //对接人
      counterpart: 2,
      //客户来源
      source: "客户介绍",
      //客户标签
      customer_label: "目标客户",
      //客户类型
      type: "私营企业",
      //客户所在城市
      city: "成都",
      //简介
      remarks: 1,
      //
    },
    {
      //隐藏属性，添加自增，用户无法直接修改
      id: 6,
      //客户名称
      name: "逗狗",
      //对接人
      counterpart: 2,
      //客户来源
      source: "客户介绍",
      //客户标签
      customer_label: "目标客户",
      //客户类型
      type: "私营企业",
      //客户所在城市
      city: "成都",
      //简介
      remarks: 1,
      //
    },
    {
      //隐藏属性，添加自增，用户无法直接修改
      id: 7,
      //客户名称
      name: "逗狗",
      //对接人
      counterpart: 2,
      //客户来源
      source: "客户介绍",
      //客户标签
      customer_label: "目标客户",
      //客户类型
      type: "私营企业",
      //客户所在城市
      city: "成都",
      //简介
      remarks: 1,
      //
    },
  ],

  //合同
  contract: [
    {
      //隐藏属性，添加自增，用户无法直接修改
      id: 1,
      //客户名称
      Client_name: "小何企业",
      //合同名称
      contract_name: "债务合同",
      //合同编号
      contract_number: "HT202005010001",
      //合同商机
      contract_opportunity: "tttttt",
      //合同金额
      contract_amount: "20000万",
      //合同状态
      contract_state: "已保存",
      //合同日期
      contract_day: "2022-11-21",
      //合同创建时间
      contract_createdDate: "2022-02-01",
      //合同内容
      contract_content: "1",
      //合同附件
      contract_fj: "",
      //创建人
      contract_Player: "1",
      //审核时间
      contract_conftime: "1",

      //回款日期
      payment_day: "1",
      //回款期次
      payment_period: "1",
      //付款方式
      payment_method: "1",
      //回款金额
      payment_amount: "1",
      //是否逾期
      isOverdue: "否",
      //银行
      bank: "中国银行",
      //账号
      account: "3456543234567",
      //逾期天数
      Overdue: "",
      //备注
      note: "",
    },
    {
      //隐藏属性，添加自增，用户无法直接修改
      id: 2,
      //客户名称
      Client_name: "小董企业",
      //合同名称
      contract_name: "借款合同",
      //合同编号
      contract_number: "HT202005010002",
      //合同商机
      contract_opportunity: "ttrrrr",
      //合同金额
      contract_amount: "1000",
      //合同状态
      contract_state: "待审核",
      //合同日期
      contract_day: "2023-01-01",
      //合同创建时间
      contract_createdDate: "2023-01-03",
      //合同内容
      contract_content: "1",
      //合同附件
      contract_fj: "",
      //创建人
      contract_Player: "1",
      //审核时间
      contract_conftime: "1",

      //回款日期
      payment_day: "1",
      //回款期次
      payment_period: "1",
      //付款方式
      payment_method: "1",
      //回款金额
      payment_amount: "1",
      //是否逾期
      isOverdue: "否",
      //银行
      bank: "中国银行",
      //账号
      account: "3456543234567",
      //逾期天数
      Overdue: "",
      //备注
      note: "",
    },
    {
      //隐藏属性，添加自增，用户无法直接修改
      id: 3,
      //客户名称
      Client_name: "猫猫头企业",
      //合同名称
      contract_name: "收养合同",
      //合同编号
      contract_number: "HT202005010003",
      //合同商机
      contract_opportunity: "tter234",
      //合同金额
      contract_amount: "112340",
      //合同日期
      contract_day: "2023-02-23",
      //合同状态
      contract_state: "待审核",
      //合同创建时间
      contract_createdDate: "2023-02-01",
      //合同内容
      contract_content: "1",
      //合同附件
      contract_fj: "",
      //创建人
      contract_Player: "1",
      //审核时间
      contract_conftime: "1",

      //回款日期
      payment_day: "1",
      //回款期次
      payment_period: "1",
      //付款方式
      payment_method: "1",
      //回款金额
      payment_amount: "1",
      //是否逾期
      isOverdue: "2",
      //银行
      bank: "中国银行",
      //账号
      account: "3456543234567",
      //逾期天数
      Overdue: "",
      //备注
      note: "",
    },
    {
      //隐藏属性，添加自增，用户无法直接修改
      id: 4,
      //客户名称
      Client_name: "企鹅企业",
      //合同名称
      contract_name: "未命名合同",
      //合同编号
      contract_number: "HT202005010004",
      //合同商机
      contract_opportunity: "tter234",
      //合同金额
      contract_amount: "112340",
      //合同状态
      contract_state: "已保存",
      //合同日期
      contract_day: "2023-02-01",
      //合同创建时间
      contract_createdDate: "2023-02-01",
      //合同内容
      contract_content: "1",
      //合同附件
      contract_fj: "",
      //创建人
      contract_Player: "1",
      //审核时间
      contract_conftime: "1",

      //回款日期
      payment_day: "1",
      //回款期次
      payment_period: "1",
      //付款方式
      payment_method: "1",
      //回款金额
      payment_amount: "1",
      //是否逾期
      isOverdue: "2",
      //银行
      bank: "中国银行",
      //账号
      account: "3456543234567",
      //逾期天数
      Overdue: "",
      //备注
      note: "",
    },
    {
      //隐藏属性，添加自增，用户无法直接修改
      id: 5,
      //客户名称
      Client_name: "大大怪企业",
      //合同名称
      contract_name: "就业合同",
      //合同编号
      contract_number: "HT202005010005",
      //合同商机
      contract_opportunity: "tter234",
      //合同金额
      contract_amount: "112340",
      //合同状态
      contract_state: "待审核",
      //合同日期
      contract_day: "2023-01-01",
      //合同创建时间
      contract_createdDate: "2023-01-01",
      //合同内容
      contract_content: "1",
      //合同附件
      contract_fj: "",
      //创建人
      contract_Player: "1",
      //审核时间
      contract_conftime: "1",

      //回款日期
      payment_day: "1",
      //回款期次
      payment_period: "1",
      //付款方式
      payment_method: "1",
      //回款金额
      payment_amount: "1",
      //是否逾期
      isOverdue: "2",
      //银行
      bank: "中国银行",
      //账号
      account: "3456543234567",
      //逾期天数
      Overdue: "",
      //备注
      note: "",
    },
    {
      //隐藏属性，添加自增，用户无法直接修改
      id: 6,
      //客户名称
      Client_name: "华城企业",
      //合同名称
      contract_name: "租赁合同",
      //合同编号
      contract_number: "HT202005010006",
      //合同商机
      contract_opportunity: "tter234",
      //合同金额
      contract_amount: "112340",
      //合同状态
      contract_state: "待审核",
      //合同日期
      contract_day: "2022-02-01",
      //合同创建时间
      contract_createdDate: "2022-03-01",
      //合同内容
      contract_content: "1",
      //合同附件
      contract_fj: "",
      //创建人
      contract_Player: "1",
      //审核时间
      contract_conftime: "1",

      //回款日期
      payment_day: "1",
      //回款期次
      payment_period: "1",
      //付款方式
      payment_method: "1",
      //回款金额
      payment_amount: "1",
      //是否逾期
      isOverdue: "2",
      //银行
      bank: "南京银行",
      //账号
      account: "3456543234567",
      //逾期天数
      Overdue: "",
      //备注
      note: "",
    },
    {
      //隐藏属性，添加自增，用户无法直接修改
      id: 7,
      //客户名称
      Client_name: "大大怪企业",
      //合同名称
      contract_name: "劳务合同",
      //合同编号
      contract_number: "HT202005010007",
      //合同商机
      contract_opportunity: "tter234",
      //合同金额
      contract_amount: "112340",
      //合同状态
      contract_state: "已保存",
      //合同日期
      contract_day: "2022-05-01",
      //合同创建时间
      contract_createdDate: "2022-07-07",
      //合同内容
      contract_content: "1",
      //合同附件
      contract_fj: "",
      //创建人
      contract_Player: "1",
      //审核时间
      contract_conftime: "1",

      //回款日期
      payment_day: "1",
      //回款期次
      payment_period: "1",
      //付款方式
      payment_method: "1",
      //回款金额
      payment_amount: "1",
      //是否逾期
      isOverdue: "2",
      //银行
      bank: "中国银行",
      //账号
      account: "3456543234567",
      //逾期天数
      Overdue: "",
      //备注
      note: "",
    },
  ],

  //  客户-商机记录-商机数据
  BusinessData: [
    {
      // 流水号
      id: 1,
      //商机标题
      title: "客户对产品1感兴趣",
      // 客户
      client: "浙江某某有限公司",
      // 意向产品
      product: "产品1",
      //主联系人
      mainClient: "张三",
      //预计签单日期,
      fixtureDate: "2020-05-01",
      // 预计销售额
      money: 2000,
      // 销售阶段
      stage: "初步洽谈",
      //商机来源
      businessSource: "朋友推荐",
      // 成交可能性
      possibility: "50%",
      // 下次跟进时间
      nextFallowTime: "2002-08-09",
      // 创建时间
      createTime: "2002-08-09",
      // 下次跟进内容
      nextFallowContent: "深入沟通",
      //备注
      remark: "",
    },
    {
      id: 2,
      title: "客户对产品1感兴趣",
      client: "浙江某某有限公司",
      product: "产品1",
      mainClient: "张三",
      fixtureDate: "2020-05-01",
      money: 2000,
      stage: "初步洽谈",
      businessSource: "朋友推荐",
      possibility: "50%",
      nextFallowTime: "2002-08-09",
      createTime: "2002-08-09",
      nextFallowContent: "深入沟通",
      remark: "",
    },
    {
      id: 3,
      title: "客户对产品1感兴趣",
      client: "浙江某某有限公司",
      product: "产品1",
      mainClient: "张三",
      fixtureDate: "2020-05-01",
      money: 2000,
      stage: "初步洽谈",
      businessSource: "朋友推荐",
      possibility: "50%",
      nextFallowTime: "2002-08-09",
      createTime: "2002-08-09",
      nextFallowContent: "深入沟通",
      remark: "",
    },
    {
      //流水号
      id: 4,
      title: "客户对产品1感兴趣",
      client: "浙江某某有限公司",
      product: "产品1",
      mainClient: "张三",
      fixtureDate: "2020-05-01",
      money: 2000,
      stage: "初步洽谈",
      businessSource: "朋友推荐",
      possibility: "50%",
      nextFallowTime: "2002-08-09",
      createTime: "2002-08-09",
      nextFallowContent: "深入沟通",
      remark: "",
    },
    {
      id: 5,
      title: "客户对产品1感兴趣",
      client: "浙江某某有限公司",
      product: "产品1",
      mainClient: "张三",
      fixtureDate: "2020-05-01",
      money: 2000,
      stage: "初步洽谈",
      businessSource: "朋友推荐",
      possibility: "50%",
      nextFallowTime: "2002-08-09",
      createTime: "2002-08-09",
      nextFallowContent: "深入沟通",
      remark: "",
    },
    {
      id: 6,
      title: "客户对产品1感兴趣",
      client: "浙江某某有限公司",
      product: "产品1",
      mainClient: "张三",
      fixtureDate: "2020-05-01",
      money: 2000,
      stage: "初步洽谈",
      businessSource: "朋友推荐",
      possibility: "50%",
      nextFallowTime: "2002-08-09",
      createTime: "2002-08-09",
      nextFallowContent: "深入沟通",
      remark: "",
    },
  ],

  //  客户-合同记录-合同数据
  contractData: [
    {
      // 序号
      id: 1,
      //合同编号
      contractSerial: "HT202005010001",
      //合同名称
      contractName: "xx合同",
      // 合同日期
      contractDate: "2020-05-01",
      // 预计销售额（万元）
      predictMoney: "1000万",
      // 已回款（万元）
      returnMoney: "200万",
      // 状态
      state: "已保存",
      // 创建时间
      createTime: "2022-02-01",
    },
    {
      id: 2,
      contractSerial: "HT202005010002",
      contractName: "xx合同",
      contractDate: "2020-05-01",
      predictMoney: "1000万",
      returnMoney: "200万",
      state: "已保存",
      createTime: "2022-02-01",
    },
    {
      id: 3,
      contractSerial: "HT202005010003",
      contractName: "xx合同",
      contractDate: "2020-05-01",
      predictMoney: "1000万",
      returnMoney: "200万",
      state: "已保存",
      createTime: "2022-02-01",
    },
    {
      id: 4,
      contractSerial: "HT202005010004",
      contractName: "xx合同",
      contractDate: "2020-05-01",
      predictMoney: "1000万",
      returnMoney: "200万",
      state: "已保存",
      createTime: "2022-02-01",
    },
    {
      id: 5,
      contractSerial: "HT202005010005",
      contractName: "xx合同",
      contractDate: "2020-05-01",
      predictMoney: "1000万",
      returnMoney: "200万",
      state: "已保存",
      createTime: "2022-02-01",
    },
    {
      id: 6,
      contractSerial: "HT202005010006",
      contractName: "xx合同",
      contractDate: "2020-05-01",
      predictMoney: "1000万",
      returnMoney: "200万",
      state: "已保存",
      createTime: "2022-02-01",
    },
  ],

  //  客户-回款记录-回款数据
  returnMoneyData: [
    {
      // 序列
      id: 1,
      // 流水号
      serial: 1,
      // 回款日期
      returnMOneyDate: "2002-02-06",
      //回款编号
      returnMoneyNum: "HT202005010001",
      // 回款期次
      returnMoneyIssue: "第一期",
      // 付款方式
      paymentMethod: "现金",
      // 回款金额
      returnMoney: "200万",
      // 是否逾期
      isOverdue: "否",
      // 状态
      state: "已保存",
      // 创建时间
      createTime: "2022-02-01",
      // 操作
    },
    {
      id: 2,
      serial: 2,
      returnMOneyDate: "2002-02-06",
      returnMoneyNum: "HT202005010002",
      returnMoneyIssue: "第一期",
      paymentMethod: "现金",
      returnMoney: "200万",
      isOverdue: "否",
      state: "已保存",
      createTime: "2022-02-01",
    },
    {
      id: 3,
      serial: 3,
      returnMOneyDate: "2002-02-06",
      returnMoneyNum: "HT202005010003",
      returnMoneyIssue: "第一期",
      paymentMethod: "现金",
      returnMoney: "200万",
      isOverdue: "否",
      state: "已保存",
      createTime: "2022-02-01",
    },
    {
      id: 4,
      serial: 4,
      returnMOneyDate: "2002-02-06",
      returnMoneyNum: "HT202005010004",
      returnMoneyIssue: "第一期",
      paymentMethod: "现金",
      returnMoney: "200万",
      isOverdue: "否",
      state: "已保存",
      createTime: "2022-02-01",
    },
    {
      id: 5,
      serial: 5,
      returnMOneyDate: "2002-02-06",
      returnMoneyNum: "HT202005010005",
      returnMoneyIssue: "第一期",
      paymentMethod: "现金",
      returnMoney: "200万",
      isOverdue: "否",
      state: "已保存",
      createTime: "2022-02-01",
    },
    {
      id: 6,
      serial: 6,
      returnMOneyDate: "2020-05-01",
      returnMoneyNum: "HT202005010006",
      returnMoneyIssue: "第一期",
      paymentMethod: "现金",
      returnMoney: "200万",
      isOverdue: "否",
      state: "已保存",
      createTime: "2022-02-01",
    },
  ],

  //  客户-跟进记录-跟进数据
  gjData: [
    {
      id: 1,
      //客户名称
      customerName: "上海潮晟文化传播有限公司",
      // 跟进方式
      gjWay: "电话访问",
      // 跟进时间
      gjTime: "2019-03-23",
      // 跟进人员
      gjPeople: "海皇",
      // 客户联系人
      contacts: "粑粑院长",
      // 创建时间
      cjTime: "2019-03-23",
      // 跟进描述
      gjDescribe: "给别人带来快乐是一件很酷的事！",
    },
    {
      id: 2,
      customerName: "上海潮晟文化传播有限公司",
      gjWay: "上门访问",
      gjTime: "2019-03-23",
      gjPeople: "高斯",
      contacts: "粑粑院长",
      cjTime: "2019-03-23",
      gjDescribe: "给别人带来快乐是一件很酷的事！",
    },
    {
      id: 3,
      customerName: "上海潮晟文化传播有限公司",
      gjWay: "电话访问",
      gjTime: "2019-03-23",
      gjPeople: "小傲",
      contacts: "粑粑院长",
      cjTime: "2019-03-23",
      gjDescribe: "给别人带来快乐是一件很酷的事！",
    },
    {
      id: 4,
      customerName: "上海潮晟文化传播有限公司",
      gjWay: "上门访问",
      gjTime: "2019-03-23",
      gjPeople: "小狗",
      contacts: "粑粑院长",
      cjTime: "2019-03-23",
      gjDescribe: "给别人带来快乐是一件很酷的事！",
    },
  ],

  agreement: [
    {
      id: 1,
      name: "",
      //合同来自的客户(存客户id)
      connection: 1,
      //签约日期
      date: "",
      //是否逾期(默认为false，逾期就为true)
      exceed: false,
      //状态(已保存、待审核、已审核，已驳回四选一)
      status: "已签约",
    },
  ],

  // 业绩
  performance: [
    {
      // id
      id: 1,
      // 负责人，姓名
      name: "张三",
      // 部门名称
      departmentName: "销售一部",
      // 年度
      oYear: "2023",
      // 年度目标
      KPI: 1200,
      // 第一季度（万元）
      firstQuarter: 300,
      // 第二季度（万元）
      secondQuarter: 300,
      // 第三季度（万元）
      thirdQuarter: 300,
      // 第四季度（万元）
      forthQuarter: 300,
      // 备注
      remarks: "",
    },
    {
      // id
      id: 2,
      // 负责人，姓名
      name: "张三",
      // 部门名称
      departmentName: "销售一部",
      // 年度
      oYear: "2023",
      // 年度目标
      KPI: 1200,
      // 第一季度（万元）
      firstQuarter: 300,
      // 第二季度（万元）
      secondQuarter: 300,
      // 第三季度（万元）
      thirdQuarter: 300,
      // 第四季度（万元）
      forthQuarter: 300,
      // 备注
      remarks: "",
    },
    {
      // id
      id: 3,
      // 负责人，姓名
      name: "张三",
      // 部门名称
      departmentName: "销售一部",
      // 年度
      oYear: "2023",
      // 年度目标
      KPI: 1200,
      // 第一季度（万元）
      firstQuarter: 300,
      // 第二季度（万元）
      secondQuarter: 300,
      // 第三季度（万元）
      thirdQuarter: 300,
      // 第四季度（万元）
      forthQuarter: 300,
      // 备注
      remarks: "",
    },
  ],

  //公告
  data: [
    {
      id: 1,
      title: "一、什么是js，js能做什么，为什么要用js",
      time: "2023/2/27 00:03:16",
      announcement:
        "JS 的定义：javascript 一门解释型语言,被浏览器解释执行(不用被编译，运行时直接解释(翻译)从上到下，一行行执行)。js 作用1.可以进行各种交互，点击，移入，移出，拖动等2.和后台的数据进行交互, 如登录3.修改样式； 通过js修改样式4.可以操作dom （添加，修改，删除），操作网页中的元素为什么要用js因为js可移植性好，绝大多数浏览器均支持JavaScript。",
    },
    {
      id: 2,
      title: "公告2",
      time: "2023/2/27 00:03:16",
      announcement: "456456456",
    },
    {
      id: 3,
      title: "公告3",
      time: "2023/2/27 00:03:16",
      announcement: "123123123",
    },
    {
      id: 4,
      title: "公告4",
      time: "2023/2/27 00:03:16",
      announcement: "123123123",
    },
    {
      id: 5,
      title: "公告5",
      time: "2023/2/27 00:03:16",
      announcement: "123123123",
    },
    {
      id: 6,
      title: "公告6",
      time: "2023/2/27 00:03:16",
      announcement: "123123123",
    },
    {
      id: 7,
      title: "公告7",
      time: "2023/2/27 00:03:16",
      announcement: "123123123",
    },
    {
      id: 8,
      title: "公告8",
      time: "2023/2/27 00:03:16",
      announcement: "123123123",
    },
    {
      id: 9,
      title: "公告9",
      time: "2023/2/27 00:03:16",
      announcement: "123123123",
    },
  ],
};

//判定浏览器是否有缓存
if (localStorage.getItem("db")) {
  //有缓存，调用缓存
  db = JSON.parse(localStorage.getItem("db"));
} else {
  //没缓存上传数据
  localStorage.setItem("db", JSON.stringify(db));
}
function asyncLocalStory() {
  localStorage.setItem("db", JSON.stringify(db));
}
let staff = db.staff; //员工
let department = db.department; //部门
let product = db.product; //产品
let connection = db.connection; //客户
let announcement = db.announcement; //公告
let agreement = db.agreement; //合同
let data = db.data;

$(window).ready(function () {
  displayData();
  addDelEvent(); //添加删除事件
  addzhezhaoEvent(); //添加遮罩事件
  addbtnaddEvent(); //添加按钮事件
  frmAddClick(); //添加组织冒泡事件
});

//显示数据
function displayData() {
  $("#tbAncmt").html("");
  localStorage.setItem("data1", JSON.stringify(data));
  let fragment = document.createDocumentFragment();
  for (let i = 0; i < data.length; i++) {
    let tr = document.createElement("tr");
    tr.innerHTML = `
        <td>${i + 1}</td>
        <td>${data[i].title}</td>
        <td>张三</td>
        <td>${data[i].time}</td>
        <td data-index='${data[i].id}'>
            <a class="view" href="Announcement-details.html?id=${
              data[i].id
            }" target="_blank">查看</a>
            <a class="del">删除</a>
        </td>
        `;
    fragment.appendChild(tr);
  }
  $("#tbAncmt").append(fragment);
}

//删除数据
function addDelEvent() {
  $("#tbAncmt").on("click", ".del", function (e) {
    let id = $(e.target).parent().attr("data-index");
    layer.msg("删除成功");
    DelDateById(id);
    displayData(); //重新加载数组
  });
}

// 根据id，删除对应数组的数据
function DelDateById(id) {
  for (let i = 0; i < data.length; i++) {
    if (data[i].id == id) {
      data.splice(i, 1);
      break;
    }
  }
}

//添加黑色背景消失的事件
function addzhezhaoEvent() {
  $("#addmodel").click(function () {
    addmodelhide();
  });
}

function addmodelhide() {
  $("#addmodel").removeClass("show");
  $("#addmodel").addClass("hide");
}

function addmodelshow() {
  $("#addmodel").removeClass("hide");
  $("#addmodel").addClass("show");
}

//点击添加按钮添加框出现事件
function addbtnaddEvent() {
  $("#btndata").click(function () {
    addmodelshow();
  });
}

//阻止冒泡
function frmAddClick() {
  $("#frmadd").click(function (e) {
    e.stopPropagation();
  });
}

//添加确定
$("#queding").click(function () {
  let date = new Date().toLocaleString();
  let ancmt = {
    id: data.length + 1 + "",
    title: $("#ancmtTitle").val(),
    time: date,
    announcement: $("#ancmtMain").val(),
  };
  data.push(ancmt);
  displayData();
  addmodelhide();
  $("#ancmtTitle").val("");
  $("#ancmtMain").val("");
});

//取消
$("#quxiao").click(function () {
  addmodelhide();
  $("#ancmtTitle").val("");
  $("#ancmtMain").val("");
});

//点击查看跳转当前公告数据
function detail() {
  let data = JSON.parse(localStorage.getItem("data1"));
  $("#announcement").html("");
  let fragment = document.createDocumentFragment();
  let id = window.location.search.split("?id=")[1] - 1;
  let div = document.createElement("div");
  div.innerHTML = `
            <h2>${data[id].title}</h2>
        <p class="p1">
            <span>发布人:</span>
            <span>张三</span>
            <span>发布时间：</span>
            <span>${data[id].time}</span>
        </p>
        <p class="p2">
            ${data[id].announcement}
        </p>
        `;
  fragment.appendChild(div);
  $("#announcement").append(fragment);
}
